// #include <stdio.h>

#define N_ELEM 5120000

int main ()
{
  int i;
  int n = N_ELEM;
  double pi, sum, x;
  double mysum = 0.0;

 {
   int regionId = createRegion ("compute_pi");

         {
          double h;
          h = 1.0 / (double) n;
          sum = 0.0;

          // #pragma llc for shared(h, n) private(x) reduction(+ : sum)
          {
	        tparams *params;
      	  tparams *prev;

		          param = (tparams *) malloc(sizeof(tparams));
                param->_base_ptr = &h;
           		 param->type = VAR_SCALAR;
                param->next = NULL;

                prev = param;
		          param = (tparams *) malloc(sizeof(tparams));
                param->_base_ptr = &h;
           		 param->type = VAR_REDUCTION;
                param->next = prev;
	              
                launch_kernel (regionId, "PiCalculation", params);

          }
          for (i = 0; i <= n; i++)
            {
              x = h * ((double) i - 0.5);
              sum += 4.0 / (1.0 + x * x);
            }

          pi = h * sum;
          }
  }

 printf ("Pi %f \n", pi);


}
